
let _OptionFinishInterval;

// 获取文本框内容的回调函数
function GetTextBoxText(control) {
    // 初始文本
    return "默认文本";
}

// 文本框内容改变时的回调函数
function OnTextBoxChange(text) {
    console.log(text)
    return true;
}

// 显示文本框内容的按钮点击事件
function ShowTextBoxContent() {
    //console.log(wps)
    // 获取文本框控件
    // var textBox = wps.ribbonUI.CommandBars.Item("customTextBox");
    // var text = textBox.text;
    
    // console.log("text:",textBox);
    let curSheet = wps.EtApplication().ActiveSheet;
    console.log("curSheet",curSheet)
    curSheet.Rows.Item(4).Hidden = true;
    console.log("Item(4)",curSheet.Rows.Item(4).Hidden = true)
    // 在WPS中显示内容
    if (text) {
        WPS.Application.ActiveSheet.Content.Text = text;
    } else {
        alert("请先在文本框中输入内容");
    }
}

// 称盒子
 function GetOption1State(){
    return false;
 }

 function OnOption1Changed(state){
	let doc = wps.EtApplication().ActiveWorkbook;
	let docName = "";
	if (!doc){
		return ;
	}
	docName = doc.Name;
    //console.log("OnOption1Changed:",state);

    if(docName.indexOf("倒模加工表") < 0){
        return false;
    }

    let curSheet = wps.EtApplication().ActiveSheet;

    if(true){
        // 遍历行,最大行200
        for(let i = 6;i<200;i++){
           let text3  = curSheet.Cells.Item(i,3).Value2;
           let text4  = curSheet.Cells.Item(i,4).Value2;
           let text17  = curSheet.Cells.Item(i,17).Value2;
           let text19  = curSheet.Cells.Item(i,19).Value2;
           //console.log("回金树:"+text17+" 回盒子:"+text19);

           let text13  = curSheet.Cells.Item(i,13).Value2;// 13&14没有数据,等于是复盅
           let text14  = curSheet.Cells.Item(i,14).Value2;
           // 先隐藏没有配金的数据栏
           if(text3 != null && text13 == null && text14 == null){
            curSheet.Rows.Item(i).Hidden = state;
           }

           if(text3 != null && text17 == null && text19 == null){
                console.log("盅号:"+text3 +" 成色:"+ text4 +" 回金树:"+text17+" 回盒子:"+text19);
                
           }else if(text3 == null && text4 == null && text17 == null && text19){
                // 空白行 不处理
           }else{
            // 隐藏已经称完盒子的行
            curSheet.Rows.Item(i).Hidden = state;
           }
        }
    }

    return true;
 }

// 称金树
 function GetOption2State(){
    return false;
 }

 function OnOption2Changed(state){
    let doc = wps.EtApplication().ActiveWorkbook;
	let docName = "";
	if (!doc){
		return ;
	}
	docName = doc.Name;
    //console.log("OnOption1Changed:",state);

    if(docName.indexOf("倒模加工表") < 0){
        return false;
    }

    let curSheet = wps.EtApplication().ActiveSheet;

    if(true){
        // 遍历行,最大行200
        for(let i = 6;i<200;i++){
           let text3  = curSheet.Cells.Item(i,3).Value2;
           let text4  = curSheet.Cells.Item(i,4).Value2;
           let text17  = curSheet.Cells.Item(i,17).Value2;
           //console.log("回金树:"+text17+" 回盒子:"+text19);

           let text13  = curSheet.Cells.Item(i,13).Value2;// 13&14没有数据,等于是复盅
           let text14  = curSheet.Cells.Item(i,14).Value2;
           // 先隐藏没有配金的数据栏
           if(text3 != null && text13 == null && text14 == null){
            curSheet.Rows.Item(i).Hidden = state;
           }

           if(text3 != null && text17 == null){
                console.log("盅号:"+text3 +" 成色:"+ text4 +" 回金树:"+text17);
                
           }else if(text3 == null && text4 == null && text17 == null){
                // 空白行 不处理
           }else{
            // 隐藏已经称完树的行
            curSheet.Rows.Item(i).Hidden = state;
           }
        }
    }

    return true;
 }

 // 收货
 function GetOption3State(){
    console.log("GetOption3State3")
    return false;
 }

 function OnOption3Changed(state){
    let doc = wps.EtApplication().ActiveWorkbook;
	let docName = "";
	if (!doc){
		return ;
	}
	docName = doc.Name;
    //console.log("OnOption1Changed:",state);

    if(docName.indexOf("倒模加工表") < 0){
        return false;
    }

    let curSheet = wps.EtApplication().ActiveSheet;

    if(true){
        // 遍历行,最大行200
        for(let i = 6;i<200;i++){
           let text3  = curSheet.Cells.Item(i,3).Value2;
           let text4  = curSheet.Cells.Item(i,4).Value2;
           let text17  = curSheet.Cells.Item(i,17).Value2;
           let text21  = curSheet.Cells.Item(i,21).Value2;
           //console.log("回金树:"+text17+" 回盒子:"+text19);

           let text13  = curSheet.Cells.Item(i,13).Value2;// 13&14没有数据,等于是复盅
           let text14  = curSheet.Cells.Item(i,14).Value2;
           // 先隐藏没有配金的数据栏
           if(text3 != null && text13 == null && text14 == null){
            curSheet.Rows.Item(i).Hidden = state;
           }
           // 隐藏没有收货的数据栏
           if(text3 != null && text17 == null){
            curSheet.Rows.Item(i).Hidden = state;
           }
           
           if(text3 != null && text21 == null){
                console.log("盅号:"+text3 +" 成色:"+ text4+" 回金树:"+ text17);
                
           }else if(text3 == null && text4 == null){
                // 空白行 不处理
           }else{
            // 隐藏已经称完树的行
            curSheet.Rows.Item(i).Hidden = state;
           }
        }
    }

    return true;
 }




 // 隐藏已完成
 function GetOptionFinishState(){
    return false;
 }

 function OnOptionFinishChanged(state){
    HideFinishRow(state);
    // if(state){
    //     _OptionFinishInterval = setInterval(function(){
    //         HideFinishRow(state);
    //     },3000);
    // }else{
    //     HideFinishRow(state);
    //     clearInterval(_OptionFinishInterval);
    // }
    return true;
 }

 function HideFinishRow(hide){
     // 通知id="Option3"的组件刷新,然后Option3就会自动调用GetOption3State方法
    // wps.ribbonUI.InvalidateControl("Option3");
    let doc = wps.EtApplication().ActiveWorkbook;
	let docName = "";
	if (!doc){
		return ;
	}
	docName = doc.Name;
    //console.log("OnOption1Changed:",state);

    if(docName.indexOf("倒模加工表") < 0){
        return false;
    }

    let curSheet = wps.EtApplication().ActiveSheet;

    if(true){
        // 遍历行,最大行200
        for(let i = 6;i<200;i++){
           let text3  = curSheet.Cells.Item(i,3).Value2; // 盅号
           let text4  = curSheet.Cells.Item(i,4).Value2; // 成色
           let text17  = curSheet.Cells.Item(i,17).Value2;// 回金树
           let text21  = curSheet.Cells.Item(i,21).Value2; // 收货
           let text23  = curSheet.Cells.Item(i,23).Value2; // 水口
           if(text3 != null && text4 != null && text17 != null && text21 != null && text23 != null ){
            curSheet.Rows.Item(i).Hidden = hide;
           }
        }
    }
 }

 function LoadFindImage(mainURL,token){
    let targetSTRING = wps.PluginStorage.getItem("select_rowtarget");
    //alert(targetSTRING)
    let Target  = $.parseJSON( targetSTRING );
    //console.log("FindImage:",Target)
    let curSheet = wps.EtApplication().ActiveSheet;
    let drumNo = curSheet.Cells.Item(Target.Row,3).Value2;
    let dateSTR = curSheet.Cells.Item(2,5).Text;
    let url = mainURL + "/kim/markImg/queryDrumNoPic.action";
    let dataObj = {"drumNo":drumNo,"dateSTR":dateSTR};
    dataObj.access_token = token;
    //alert(url)
    ActionJS.AjaxPostSP(url,dataObj,function(result){
        //alert(result.errorMsg)
        if(result.errorCode != 1000){
            alert(result.errorMsg);
        }else{
               // 1. 获取 img 元素
        const img = document.getElementById("frameImage");
        img.src = mainURL + "/pkg/web/" + result.errorMsg;
        }
    });
 }